
package main;
import java.io.*;

public class datastream extends Thread{
    private Main main;
    private BufferedReader in;
    private boolean run;
    public String serverName;
    public datastream(Main main,BufferedReader in, String serverName)
    {
        this.serverName = serverName;
        this.main=main;
        this.in=in;
        run=true;
        this.start();
    }
    @Override
    public void run()
    {
        String input;
        while(run)
        {
            
            System.out.println("Client "+main.username+" is listening: Server "+serverName);
            try{
                //Thread.sleep(200);
                input=in.readLine();
                System.out.println("Client "+main.username+" da nhan duoc SMS: "+input);
                main.readMSG(input);
            }catch(Exception e)
            {
                System.err.println(e);
            }
        }
        try{
            in.close();
        }catch(Exception e)
        {
            System.err.print(e);
        }
    }
    public void stopThread()
    {
        this.run=false;
    }

}
